<template>
	<view class="wh">
		<template v-for="(item, index) in chatHomeList" :key="index">
			<view class="List Left" :id="`chat${index}`" v-if="item.state == 1">
				<view class="HeadBox">
					<image :src="item.img" mode="aspectFill" class="Headimgs"></image>
					<view class="d-flex a-center p-top10" v-if="item.isshow">
						<text class="tipTxt">静音</text>
						<image
							:src="staticImg('icon_sound@2x.png')"
							mode="aspectFill"
							class="soundImg"></image>
					</view>
				</view>
				<view class="content" v-if="item.type == 1 || item.type == 3">
					<view class="content_text">
						<view class="answer">{{ item.answer }}</view>
						<!-- 单选 -->
						<template v-if="item.type == 1">
							<view
								class="single_choice"
								v-for="(sub, subIn) in item.recommend"
								:key="subIn"
								@click.stop="single_choice(item, sub, index)"
								>{{ sub.index }}.{{ sub.question }}
							</view>
						</template>
						<!-- 多选 -->
						<view class="rows" v-if="item.type == 3">
							<up-checkbox-group
								v-model="checkboxValue1"
								placement="column"
								@change="checkboxChange">
								<view
									class="Multiple_choice"
									:class="{ Nochoice: !item.allowclick }"
									v-for="(sub, subIn) in item.recommend">
									<up-checkbox
										:customStyle="{ marginBottom: '8px' }"
										:key="subIn"
										size="14"
										labelSize="13"
										iconSize="10"
										:labelColor="mainStore.color"
										:label="`${sub.index}.${sub.question}`"
										:name="sub.question">
									</up-checkbox>
								</view>
							</up-checkbox-group>
							<view
								class="configBtn"
								:class="{ active: checkboxValue1.length }"
								v-if="item.allowclick"
								@click="configMultiple(item)"
								>确定</view
							>
						</view>
					</view>
				</view>

				<view class="content" v-else>
					<view class="content_text bgFa">
						<view class="answer">{{ item.answer }}</view>
					</view>
					<!-- 跳转 -->
					<view class="skip" v-if="item.type == 601" @click="skipUrl(item)">
						<text class="nameTitle">{{ item.tourlDescription }}</text>
						<view class="iconfont icon-xiangyou color-999 size44"></view>
					</view>
				</view>
			</view>
			<view class="List Right" :id="`chat${index}`" v-if="item.state == 2">
				<view class="content">
					<view class="content_text">{{ item.question }}</view>
					<view class="Edit_error" v-if="item.isshow">
						<text class="discern">识别错误？</text>
						<text class="Edit">修改</text>
					</view>
				</view>
				<view class="HeadBox">
					<image :src="item.img" mode="aspectFill" class="Headimgs"></image>
				</view>
			</view>
		</template>

		<defaultNiu v-if="!chatHomeList.length"></defaultNiu>
	</view>
</template>

<script setup>
	import defaultNiu from '@/components/Home/defaultNiu.vue';
	import { ref, defineEmits } from 'vue';
	import {
		toUrl,
		toLogin,
		Toast,
		formatter,
		tampToDate,
		staticImg,
		imgUrls,
		showLoading,
		hideLoading,
	} from '@/utils/utils.js';
	import { useMainStore } from '@/stores/index';
	const mainStore = useMainStore();
	const props = defineProps(['chatHomeList']);
	const emit = defineEmits(['sendContent']);
	const checkboxValue1 = ref([]); // 多选

	const single_choice = (Item, Sub, Index) => {
		// 单选
		if (!Item.allowclick) return;
		Item.allowclick = false;
		emit('sendContent', Sub.question);
	};

	const configMultiple = (Item) => {
		// 多选
		if (!checkboxValue1.value.length) return;
		Item.allowclick = false;
		const result = checkboxValue1.value.join('\n');
		emit('sendContent', result);
	};

	const checkboxChange = (n) => {
		console.log('change', n);
	};

	const skipUrl = (item) => {
		if (!item.tourl) return;
		toUrl(item.tourl);
	};
</script>

<style lang="scss" scoped>
	.List {
		width: 100%;
		display: flex;
		padding-top: 20rpx;

		.content {
			width: 100%;
			.bgFa {
				background-color: #fbfbfb !important;
			}
			&_text {
				display: inline-block;
				padding: 14rpx 20rpx;
				background-color: #ffffff;

				font-size: 28rpx;
				line-height: 40rpx;
				margin-top: 20rpx;
			}
		}

		.HeadBox {
			display: flex;
			flex-direction: column;
			align-items: center;

			.Headimgs {
				width: 88rpx;
				height: 88rpx;
				border-radius: 4rpx;
				overflow: hidden;
			}
		}
	}

	.Left {
		padding-right: 180rpx;
		justify-content: flex-start;

		.content_text {
			border-radius: 0 20rpx 20rpx 20rpx;
			border: 1rpx solid rgba(0, 0, 0, 0.1);

			.answer {
				color: #333;
				font-size: 28rpx;
			}

			.single_choice {
				width: 100%;
				padding: 14rpx 20rpx;
				color: $color_008;
				font-size: 26rpx;
				background-color: #f7f7f7;
				margin-top: 16rpx;
				border-radius: 6rpx;
			}

			.Multiple_choice {
				width: 100%;
				padding: 4rpx 20rpx;
				color: $color_008;
				font-size: 26rpx;
				background-color: #f7f7f7;
				margin-top: 14rpx;
				border-radius: 6rpx;

				::v-deep .u-checkbox__icon-wrap {
					flex-shrink: 0 !important;
				}
			}

			.Nochoice {
				::v-deep .u-checkbox__icon-wrap {
					display: none !important;
				}
			}

			.configBtn {
				width: 100%;
				height: 70rpx;
				background-color: #f7f7f7;
				color: #999;
				font-size: 30rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				border-radius: 10rpx;
				margin-top: 20rpx;
			}

			.active {
				background-color: $color_008 !important;
				color: #fff !important;
			}
		}

		.tipTxt {
			color: #9a9ea2;
			font-size: 20rpx;
		}

		.soundImg {
			width: 28rpx;
			height: 24rpx;
			margin-left: 4rpx;
		}

		.content {
			margin-left: 20rpx;
		}
	}

	// 跳转
	.skip {
		width: 100%;
		background-color: #fff;
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		padding: 30rpx 24rpx;
		border-radius: 0 20rpx 20rpx 20rpx;
		.nameTitle {
			color: #000;
			font-size: 28rpx;
			flex: 1;
		}
	}

	.Right {
		padding-left: 180rpx;
		justify-content: flex-end;

		.content {
			margin-right: 20rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-end;

			.content_text {
				color: #fff;
				border-radius: 20rpx 0 20rpx 20rpx;
				background-color: v-bind('mainStore.color');
			}

			.Edit_error {
				display: flex;
				align-items: center;
				padding-top: 10rpx;

				.discern {
					color: #9a9ea2;
					font-size: 20rpx;
				}

				.Edit {
					color: v-bind('mainStore.color');
					font-size: 20rpx;
				}
			}
		}
	}
</style>
